home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: How to the size of a file in C ?
- Date: 10 Feb 1996 20:12:35 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4fiu7j$ikl@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe8.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 09, 1996 12:31:06 in article <How to the size of a file in C ?>,
- 'Gilbert Banks <gilbertb@bnr.ca>' wrote:
-
-
- >How do I get the size of a file in C UNIX-based? I tried sizeof <file>,
- but
- >that only returns the size of the object called "<file>" and not the data.
-
- >I know about filelength(), also, but that is DOS, Windows, and OS/2.
- >
- There are other (better?) ways, but the one that has worked
- for me for many years , and is portable across the platforms
- mentioned plus some:
-
- 1. Open the file in binary mode fopen("foo.bar", "rb");
- 2. Move the file pointer to its end using fseek();
- 3. Query the file position with ftell();
- 4. Either close (fclose()) or rewind the file with fseek().
-
- I've also used a c++ version with fstreams using seekg
- and tellg but have not had a chance to test it on Unix
- platforms other than Solaris 2.3.
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-